#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QDir>
#include <QFileInfoList>
#include <QFileInfo>
#include <QDebug>
#include <QTextCodec>

#include <QTcpServer>
#include <QTcpSocket>
#include <QDateTime>

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <QDesktopServices>
#include <QAndroidJniObject>
#include <QAndroidJniEnvironment>

using namespace std;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    void send_str(char sendBuf[]);

    bool server_recv(char recv_buf[]);

    void getSubStr(char src[], char dst[], int n);
    bool cmp_str(const char src[], const char dst[]);
    bool send_file(char filename[],char label[]);

    void sendFile(char srcFilename[]);

    int getFileInfo(char filename[]);
    void getDirInfo(char filename[]);

    int getMessageSize(char str[], int &num);

    void recv1024(char recvBuf[])
    {
        int recvLen=0;
        while(1)
        {
            int size = tcpSocket->read(&recvBuf[recvLen],1024-recvLen);
            recvLen += size;
            if(recvLen==1024)
                break;
        }
    }
    
    void sendFileList(char str[]);

    void detectName(char name[])
    {
        for(int i=0;i<strlen(name);i++)
        {
            if(name[i]=='|')
                name[i]=' ';
        }
    }


private slots:
    void on_start_clicked();

    void on_start2_clicked();

    void on_start_2_clicked();

    void on_start_3_clicked();

    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;

    QTcpServer  *tcpServer;//监听套接字
    QTcpSocket  *tcpSocket;//通信套接字
    bool isOpen;
    FILE *rfp;
    int recvLen;
    char recvBuf[1024];
    bool lightOn;
    QAndroidJniObject m_wakeLock;
};

#endif // MAINWINDOW_H
